home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / -in_the_mag- / emulation / consoles / amigavgb / z80.h < prev   
C/C++ Source or Header  |  1997-12-12  |  5KB  |  121 lines

  1. /** VGB: portable GameBoy emulator ***************************/
  2. /**                                                         **/
  3. /**                           Z80.h                         **/
  4. /**                                                         **/
  5. /** This file contains declarations relevant to emulation   **/
  6. /** of Z80 CPU. See GB.h for #defines related to drivers    **/
  7. /** and GameBoy emulation.                                  **/
  8. /**                                                         **/
  9. /** Copyright (C) Marat Fayzullin 1994,1995,1996            **/
  10. /**     You are not allowed to distribute this software     **/
  11. /**     commercially. Please, notify me, if you make any    **/
  12. /**     changes to this file.                               **/
  13. /*************************************************************/
  14.  
  15. /* #define DEBUG */            /* Compile debugging version  */
  16. /* #define LSB_FIRST */        /* Compile for low-endian CPU */
  17.  
  18. #define S_FLAG      0x80
  19. #define Z_FLAG      0x40
  20. #define H_FLAG      0x10
  21. #define P_FLAG      0x04
  22. #define V_FLAG      0x04
  23. #define N_FLAG      0x02
  24. #define C_FLAG      0x01
  25.  
  26. /**********************************************************/
  27. /*** NOTICE: sizeof(byte)=1 and sizeof(word)=2          ***/
  28. /**********************************************************/
  29. typedef unsigned char byte;
  30. typedef unsigned short word;
  31. typedef signed char offset;
  32.  
  33. /**********************************************************/
  34. /*** #define LSB_FIRST for machines where least         ***/
  35. /*** signifcant byte goes first.                        ***/
  36. /**********************************************************/
  37. typedef union
  38. {
  39. #ifdef LSB_FIRST
  40.   struct { byte l,h; } B;
  41. #else
  42.   struct { byte h,l; } B;
  43. #endif
  44.   word W;
  45. } pair;
  46.  
  47. typedef struct
  48. {
  49.   pair AF,BC,DE,HL,PC,SP;
  50.   byte IFF,I;
  51. } reg;
  52.  
  53. /*** Interrupts *******************************************/
  54. /*** Interrupt-related variables.                       ***/
  55. /**********************************************************/
  56. extern int  IPeriod;  /* Number of cycles between internal interrupts */
  57. extern byte IntSync;  /* Generate internal interrupts if IntSync==1   */
  58. extern byte IFlag;    /* If IFlag==1, generate interrupt and set to 0 */
  59.  
  60. /*** Trace and Trap ***************************************/         
  61. /*** Switches to turn tracing on and off in DEBUG mode. ***/
  62. /**********************************************************/
  63. #ifdef DEBUG
  64. extern byte Trace;  /* Tracing is on if Trace==1  */
  65. extern word Trap;   /* When PC==Trap, set Trace=1 */
  66. #endif
  67.  
  68. /*** TrapBadOps *******************************************/
  69. /*** When 1, print warnings of illegal Z80 instructions.***/
  70. /**********************************************************/
  71. extern byte TrapBadOps;
  72.  
  73. /*** CPURunning *******************************************/
  74. /*** When 0, execution terminates.                      ***/
  75. /**********************************************************/
  76. extern byte CPURunning;
  77.  
  78. /*** Reset Z80 registers: *********************************/
  79. /*** This function can be used to reset the register    ***/
  80. /*** file before starting execution with Z80(). It sets ***/
  81. /*** the registers to their initial values.             ***/
  82. /**********************************************************/
  83. void ResetZ80(reg *Regs);
  84.  
  85. /*** Interpret Z80 code: **********************************/
  86. /*** Registers have initial values from Regs. PC value  ***/
  87. /*** at which emulation stopped is returned by this     ***/
  88. /*** function.                                          ***/
  89. /**********************************************************/
  90. /*** Interpret Z80 code: **********************************/
  91. /*** Registers have initial values from Regs. PC value  ***/
  92. /*** at which emulation stopped is returned by this     ***/
  93. /*** function.                                          ***/
  94. /**********************************************************/
  95. word Z80(reg Regs);
  96.  
  97. /**********************************************************/
  98. /*** These functions are called when read or write to   ***/
  99. /*** RAM occurs. They perform actual reads abd writes.  ***/
  100. /**********************************************************/
  101. void M_WRMEM(word A,byte V);
  102. byte M_RDMEM(word A);
  103.  
  104. #ifdef DEBUG
  105. /*** Single-step debugger *********************************/
  106. /*** This function should exist if DEBUG is #defined.   ***/
  107. /*** If Trace==1 it is called after each command        ***/
  108. /*** executed by the CPU and given a pointer to the     ***/
  109. /*** register file.                                     ***/
  110. /**********************************************************/
  111. void Debug(reg *R);
  112. #endif
  113.  
  114. /*** Interrupt handler ************************************/
  115. /*** This function should exist if INTERRUPTS is        ***/
  116. /*** #defined. It is called on each attempted interrupt ***/
  117. /*** and should return an interrupt address to proceed  ***/
  118. /*** with interrupt or 0xFFFF to continue execution.    ***/ 
  119. /**********************************************************/
  120. word Interrupt(void);
  121.